#!/bin/sh

source /AIR_FLASH/system/air_sys.conf
source /AIR_FLASH/script/air.conf
#default
ftpUser=htgw
ftpPwd=123456
ftpRoot=/upload/htgw

linuxName=`uname -r`
if [ "${HWVersion}" == "V0" ] ; then
    if [ ! -d "/etc/vsftpd" ] ; then
        mkdir -p /etc/vsftpd   
        cp $prefix/ftpFile/chroot_list /etc/vsftpd/
        cp $prefix/ftpFile/user_list /etc/vsftpd/
        cp $prefix/ftpFile/vsftpd.conf /etc/

        mkdir -p /usr/share/empty

        echo /bin/bash >> /etc/shells
        echo /sbin/nologin >> /etc/shells    
    fi
    vsftpd -v 
    if [ $? -ne 0 ] ; then
        cp $prefix/ftpFile/vsftpd /usr/sbin
    fi
fi
test=`cat /etc/passwd | grep ${ftpUser} | wc -l`

if [ $test -eq 1 ]; then
    echo "${ftpUser} is created"
    if [ ! -d ${ftpRoot} ] ; then
        mkdir -p ${ftpRoot}
	chmod 777 ${ftpRoot}
        chown ${ftpUser} ${ftpRoot}
	echo "create FTP root path ${ftpRoot}"
    fi
else
    mkdir -p ${ftpRoot}
    chmod 777 ${ftpRoot}
    useradd ${ftpUser} -d ${ftpRoot} -s /sbin/nologin
    chown ${ftpUser} ${ftpRoot}
    echo "${ftpUser}:${ftpPwd}" | chpasswd 
fi

killall -9 vsftpd > /dev/null 2&>1

vsftpd &
